<template>
  <div>
    <el-container>
      <el-header class="layout-header">
        <el-menu
            router
            :default-active="activeIndex2"
            class="el-menu-demo"
            mode="horizontal"
            @select="handleSelect"
            background-color="#ec6c0a"
            text-color="#fff"
            active-text-color="#ffd04b">
          <el-menu-item index="/consumer/index">我的家政</el-menu-item>
          <el-submenu index="2" mode="horizontal">
            <template slot="title">账户设置</template>
            <el-submenu >
              <template slot="title">安全设置</template>
              <el-menu-item index="/consumer/up-password">修改登录密码</el-menu-item>
              <el-menu-item index="/consumer/up-phone">手机绑定</el-menu-item>
            </el-submenu>

            <el-submenu index="2-4">
              <template slot="title">个人资料</template>
              <el-menu-item index="/consumer/up-address">收货地址</el-menu-item>
              <el-menu-item index="/consumer/up-info">修改昵称、头像</el-menu-item>
            </el-submenu>
          </el-submenu>
          <el-button type="warning" @click="goToindex">去首页</el-button>

        </el-menu>

      </el-header >
      <el-main class="layout-main">
        <router-view/>
      </el-main>
    </el-container>

  </div>
</template>

<style>
.layout-header {
  background: #ec6c0a;
}

.layout-header h1 {
  color: #fff;
  line-height: 60px;
}

.layout-body {
  position: absolute;
  top: 60px;
  bottom: 0;
  left: 0;
  right: 0;
}

.layout-aside {
  background: #222;
}

.layout-aside i {
  color: #fff !important;
}

.layout-main {
  background: #fff;
}

.el-menu-item.is-active {
  background: #ffffff !important;
}
</style>

<script>
export default {
  data() {
    return {
      user: {}
    }
  },
  methods: {
    goToindex() {
      console.log("点了")
      var path = this.$route.path;
      if (path!="/"){
        this.$router.push({name:"index"})
      }

    },
    loadUser() {
      let url = 'http://localhost:9081/user/'+this.userId;
      console.log('url = ' + url);

      this.axios.get(url).then((response) => {
        let responseBody = response.data;
        console.log(responseBody);
        if (responseBody.state == 20000) {
          this.$message({
            showClose: true,
            message: '查询成功！',
            type: 'success'
          });
          this.user = responseBody.data;
          console.log(this.user)
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });
    },
  },
  mounted() {
    console.log("个人首页初始化“：")
    // this.userId=this.$route.query.userId
    // console.log('当前的用户id：',this.userId)
    // if (this.userId != null) {
    //   this.loadUser();
    // }
    // location.reload();
  },
  watch: {
    '$route'() {
      console.log("个人首页初始化“：",data)
      this.userId=this.$route.query.userId
      console.log('当前的用户id：',this.userId)
      if (this.userId != null) {
        this.loadUser();
      }
      location.reload();

    }
  },

}
</script>